<template>
  <!--印章档案管理-->
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请人">
              <j-select-user-by-dep :multi="false" v-model="queryParam.createBy" placeholder="请选择申请人" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请部门">
              <j-select-depart v-model="queryParam.handlerDeptId" placeholder="请选择申请部门" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="印章编号">
              <a-input placeholder="请输入印章编号" v-model="queryParam.sealQualificationId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="名称">
              <a-input placeholder="请输入名称" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="印章类别">
              <j-dict-select-tag placeholder="请选择印章类别" v-model="queryParam.sealType" dictCode="yzlx_type"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="状态">
              <j-dict-select-tag placeholder="请选择状态" v-model="queryParam.status" dictCode="seal_status_type"/>
            </a-form-item>
          </a-col>
          <!-- <template v-if="toggleSearchStatus"></template> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery()" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button
        @click="handleAddYz"
        type="primary"
        icon="plus"
        :disabled="isDisabledAuth('erpSealCertificateFileManage:add')">新建印章
      </a-button>
      <!--      <a-button @click="handleAddZz" type="primary" icon="plus"-->
      <!--                :disabled="isDisabledAuth('erpSealCertificateFileManage:add')">新建证照-->
      <!--      </a-button>-->
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('印章档案管理')"
                :disabled="isDisabledAuth('erpSealCertificateFileManage:export')">导出
      </a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
                @change="handleImportExcel">
        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpSealCertificateFileManage:import')">导入
        </a-button>
      </a-upload> -->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpSealCertificateFileManage:delete')">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12" :key="index">
                    <a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox>
                  </a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;">
          <a-icon type="setting" :style="iconStyle"/>
        </a>
      </a-popover>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
          style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,getCheckboxProps: getCheckboxProps}"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <a slot="detail" :title="text" slot-scope="text, record" @click="getDetail(record.id)">{{ text }}</a>
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a-button
            class="ruleButton"
            :ghost="true"
            type="primary"
            icon="edit"
            @click="handleEdit(record)"
            :disabled="isDisabledAuth('erpSealCertificateFileManage:edit')"
          />
          <a-divider type="vertical"/>
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a-button
              class="ruleButton"
              :ghost="true"
              type="primary"
              icon="delete"
              :disabled="isDisabledAuth('erpSealCertificateFileManage:delete')"/>
          </a-popconfirm>
        </span>
      </a-table>
    </div>

    <erp-seal-certificate-file-manage-modal-yz ref="modalFormYz" @ok="modalFormOk"></erp-seal-certificate-file-manage-modal-yz>
    <erp-seal-certificate-file-manage-modal-zz ref="modalFormZz" @ok="modalFormOk"></erp-seal-certificate-file-manage-modal-zz>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ErpSealCertificateFileManageModalYz from './modules/ErpSealCertificateFileManageModalYz'
import ErpSealCertificateFileManageModalZz from './modules/ErpSealCertificateFileManageModalZz'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'

export default {
  name: 'ErpSealCertificateFileManageList',
  mixins: [JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
    ErpSealCertificateFileManageModalYz,
    ErpSealCertificateFileManageModalZz,
    SelectUserByDep
  },
  data() {
    return {
      description: '印章档案管理管理页面',
      // 表头
      columns: [],
      // 列设置
      settingColumns: [],
      // 列定义
      defColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '编号',
          align: 'center',
          width: 200,
          dataIndex: 'sealQualificationId',
          scopedSlots: { customRender: 'detail' },
          ellipsis: true
        },
        {
          title: '名称',
          align: 'center',
          dataIndex: 'name',
          width: 200,
          ellipsis: true
        },
        {
          title: '印章类别',
          align: 'center',
          width: 200,
          dataIndex: 'sealType_dictText',
          ellipsis: true
        },
        {
          title: '所属公司',
          align: 'center',
          width: 400,
          dataIndex: 'sealCompany_dictText',
          ellipsis: true
        },
        {
          title: '负责人',
          align: 'center',
          width: 100,
          dataIndex: 'sealCertificationHead_dictText',
          ellipsis: true
        },
        {
          title: '保管员',
          align: 'center',
          width: 100,
          dataIndex: 'trustee_dictText',
          ellipsis: true
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'status_dictText',
          ellipsis: true
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 160,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],
      url: {
        list: '/api/erp/administration/seal/erpSealCertificateFileManage/list',
        delete: '/api/erp/administration/seal/erpSealCertificateFileManage/delete',
        deleteBatch: '/api/erp/administration/seal/erpSealCertificateFileManage/deleteBatch',
        exportXlsUrl: '/api/erp/administration/seal/erpSealCertificateFileManage/exportXls',
        importExcelUrl: 'administration/seal/erpSealCertificateFileManage/importExcel'
      },
      dictOptions: {},
      superFieldList: []
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    nullify: function () {
      this.is_show = true;
      this.$refs.nullify.add(this.is_show);
      this.$refs.nullify.title = '作废';
      this.$refs.nullify.disableSubmit = false;
    },
    handleAddYz: function () {
      this.is_show = true;
      this.$refs.modalFormYz.add(this.is_show);
      this.$refs.modalFormYz.title = '新建印章';
      this.$refs.modalFormYz.disableSubmit = false;
    },
    handleAddZz: function () {
      this.is_show = true;
      this.$refs.modalFormZz.add(this.is_show);
      this.$refs.modalFormZz.title = '新建证照';
      this.$refs.modalFormZz.disableSubmit = false;
    },
    handleEdit(record) {
      this.$refs.modalFormYz.edit(record);
      this.$refs.modalFormYz.title = '修改';
      this.$refs.modalFormYz.disableSubmit = false;
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'datetime', value: 'createTime', text: '创建日期' })
      fieldList.push({ type: 'string', value: 'handlerId', text: '申请人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'handlerDeptId', text: '申请部门', dictCode: '' })
      fieldList.push({ type: 'string', value: 'sealQualificationId', text: '印章编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'name', text: '名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'sealType', text: '印章类别', dictCode: 'yzlx_type' })
      fieldList.push({
        type: 'string',
        value: 'sealCompany',
        text: '印章所属公司',
        dictCode: 'erp_company_files,file_name,id'
      })
      fieldList.push({ type: 'string', value: 'sealCertificationHead', text: '印章负责人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'authorizedPerson', text: '授权责任人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'delegate', text: '委托方', dictCode: 'erp_company_files,file_name,id' })
      fieldList.push({ type: 'string', value: 'trustee', text: '被委托方（印章保管人）', dictCode: 'erp_employee_file,name,id' })
      fieldList.push({ type: 'date', value: 'entrustDateStart', text: '委托开始时间' })
      fieldList.push({ type: 'date', value: 'entrustDateEnd', text: '委托结束时间' })
      fieldList.push({ type: 'string', value: 'sealCertificationUseScope', text: '印章使用范围', dictCode: '' })
      fieldList.push({ type: 'string', value: 'attentionMatters', text: '注意事项', dictCode: '' })
      fieldList.push({ type: 'string', value: 'upload', text: '上传附件', dictCode: '' })
      fieldList.push({ type: 'string', value: 'status', text: '状态', dictCode: 'seal_status_type' })
      this.superFieldList = fieldList
    },
    // 查看详情
      getDetail(id) {
        this.$router.push({
          path: `/erp/administration/seal/ErpSealCertificateFileManageListDetail/${id}`
        })
      },
    // 流程审批结束禁用
    getCheckboxProps(record) {
      return {
        props: {
          disabled: record.bpmStatus !== '1'
        }
      }
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
